<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="12">
            <a-form-model-item label="客户" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="keHu">
              <a-input v-model="model.keHu" placeholder="请输入客户"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="料号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="liaoHao">
              <a-input v-model="model.liaoHao" placeholder="请输入料号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="pinMing">
              <a-input v-model="model.pinMing" placeholder="请输入品名"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="供应商" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gongYingShang">
              <a-input v-model="model.gongYingShang" placeholder="请输入供应商"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="物料版本号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="wuLiaoBanBenHao">
              <a-input v-model="model.wuLiaoBanBenHao" placeholder="请输入物料版本号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="生产日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shengChanRiQi">
              <a-input v-model="model.shengChanRiQi" placeholder="请输入生产日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交货数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jiaoHuoShuLiang">
              <a-input v-model="model.jiaoHuoShuLiang" placeholder="请输入交货数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="单箱数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="danXiangShuLiang">
              <a-input v-model="model.danXiangShuLiang" placeholder="请输入单箱数量"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="交货日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="jiaoHuoRiQi">
              <a-input v-model="model.jiaoHuoRiQi" placeholder="请输入交货日期"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="供应商编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gongYingShangBianMa">
              <a-input v-model="model.gongYingShangBianMa" placeholder="请输入供应商编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="批次号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="piCiHao">
              <a-input v-model="model.piCiHao" placeholder="请输入批次号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="条码编码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tiaoMaBianHao">
              <a-input v-model="model.tiaoMaBianHao" placeholder="请输入条码编码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="12">
            <a-form-model-item label="二维码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="qrcode">
              <a-input v-model="model.qrcode" placeholder="请输入二维码"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'BarCodeForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          keHu:"至像（山东）科技有限公司",
          gongYingShang:"深圳市昌红科技有限公司",
          gongYingShangBianMa:"P000194"

         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          keHu:[
              { required: true, message: '请输入客户!'},
           ],
           liaoHao:[
              { required: true, message: '请输入料号!'},
           ],
           pinMing:[
              { required: true, message: '请输入品名!'},
           ],
           gongYingShang:[
              { required: true, message: '请输入供应商!'},
           ],
           wuLiaoBanBenHao:[
              { required: true, message: '请输入物料版本号!'},
           ],
           shengChanRiQi:[
              { required: true, message: '请输入生产日期!'},
           ],
           jiaoHuoShuLiang:[
              { required: true, message: '请输入交货数量!'},
           ],
           danXiangShuLiang:[
              { required: true, message: '请输入单箱数量!'},
           ],
           jiaoHuoRiQi:[
              { required: false, message: '请输入交货日期!'},
           ],

        },
        url: {
          add: "/ch/barCode/add",
          edit: "/ch/barCode/edit",
          queryById: "/ch/barCode/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>